<?php
  session_start();
  header("content-type=textml; charset=utf-8");  //设置字符集
  require("config.php");  //包含数据库连接文件
  $depart  = $_POST['depart'];  
//判断部门是否已经存在
  $s_ql="SELECT * FROM depart";
  $result = mysql_query($s_ql);
  $name = mysql_fetch_array($result);
  if(($name['d_name'])!=$depart)
  {
	 $insert="INSERT INTO depart (`d_name`) VALUES ('$depart')";
	 $r = mysql_query($insert);// 返回结果集，成功true，失败false
  }
  if($result && mysql_affected_rows()>0)
  {
	  echo "<script>alert('部门名添加成功！');window.location.href='depart.php';</script>";
  }
//mysql_free_result($result);
//mysql_free_result($rs);
mysql_close($con);
 ?>